import json
from vulcanus.log.log import LOGGER
from zeus.operation_service.app.proxy.asset import AssetProxy
from zeus.operation_service.app.core.framework.common.constant import TaskType
from zeus.operation_service.app.core.framework.task.task_detail.task_detail import TaskDetail


class DataCollectDetail(TaskDetail):

    def generate_asset_items_info(self, asset):
        LOGGER.warning("get data_collect_items begin")
        asset_items_list = list()
        asset_items = AssetProxy().get_asset_item(asset.asset_id, TaskType.DATA_COLLECT)
        for asset_item in asset_items:
            asset_item_info = dict()
            asset_item_info['id'] = asset_item.item_id
            asset_item_info['item_path'] = asset_item.item_path
            item_detail = json.loads(asset_item.item_detail)
            item_name = dict()
            item_name['zh'] = item_detail['name']['@name_zh']
            item_name['en'] = item_detail['name']['@name_en']
            asset_item_info['item_name'] = item_name
            asset_items_list.append(asset_item_info)
        return asset_items_list
